package com.mcptt.http.operator.online;


import java.util.Date;
import java.util.List;
import java.util.Vector;

import com.cloudptt.api.models.lbs.LocationData;
import com.mcptt.db.model.MapPointInfo;

import android.util.Log;

public class OnlineParser 
{
	public OnlineParser()
	{}
	public static List<MapPointInfo> parseContentStr(String bodyStr) {
		Log.d("OnlineParser", "parseContentStr bodyStr = " + bodyStr);
		List<MapPointInfo> userList = new Vector<MapPointInfo>();

		String[] strArr = bodyStr.split("\n");
		for(int i = 0; i < strArr.length; i++)
		{
			Log.d("OnlineParser", "parseContentStr strArr[" + i + "] = " + strArr[i]);
			String str = strArr[i];
			Log.d("OnlineParser", "parseContentStr str = " + str);
			if(str != null
					&& str.length() > 0)
			{
				String[] attr = str.split("@");
				if(attr != null
						&& attr.length == 2)
				{
					String mcId = attr[0];
					String ip =  attr[1];
					Log.d("OnlineParser", "parseContentStr mcId = " + mcId + " ip = " + ip);
					String[] ipAttr = ip.split(":");
					if(ipAttr != null
							&& ipAttr.length == 2)
					{
						ip = ipAttr[0];
					}
					Date d = new Date();
					long time = d.getTime();
					LocationData locData = LocationData.getDefaultLocationData();
					MapPointInfo point = new MapPointInfo(mcId,MapPointInfo.MapPointType_GPS,time,locData,"",ip);
					Log.d("OnlineParser", "parseContentStr point = " + point);
					userList.add(point);
				}
			}
		}
		return userList;
	}
	//	public static List<MapPointInfo> parseContentStr(String bodyStr) {
	//		Log.d("OnlineParser", "parseContentStr bodyStr = " + bodyStr);
	//		List<MapPointInfo> userList = new Vector<MapPointInfo>();
	//		Map<String,String> idMap = new HashMap<String,String>();
	//		String[] strArr = bodyStr.split("\n");
	//		for(int i = 0; i < strArr.length; i++)
	//		{
	//			Log.d("OnlineParser", "parseContentStr strArr[" + i + "] = " + strArr[i]);
	//			String[] value = strArr[i].split("\\|");
	//			String mcId = value[0];
	//			Log.d("OnlineParser", "parseContentStr mcId = " + mcId);
	//			if(idMap.get(mcId) == null)
	//			{
	//				Date d = new Date();
	//				long time = d.getTime();
	//				LocationData locData = LocationData.getDefaultLocationData();
	//				MapPointInfo point = new MapPointInfo(value[0],MapPointInfo.MapPointType_GPS,time,locData,"");
	//				Log.d("OnlineParser", "parseContentStr point = " + point);
	//				userList.add(point);
	//				idMap.put(mcId, mcId);
	//			}
	//		}
	//		return userList;
	//	}
}
